//package com.qf.consumer.config;
//
//
//
//import com.rabbitmq.client.Channel;
//import com.rabbitmq.client.ConnectionFactory;
//import org.springframework.amqp.core.*;
//import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
//import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
//import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
//import org.springframework.amqp.support.ConsumerTagStrategy;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.HashMap;
//import java.util.Map;
//import java.util.UUID;
//
//
//@Configuration
//public class RabbitMQConfiguration {
//    //声明队列
//    @Bean
//    public Queue queue1() {
//        Map<String, Object> args = new HashMap<>(2);
//
//        Queue queue1 = new Queue("queue1");
//        //设置队列属性
//        return queue1;
//    }
//    @Bean
//    public Queue queue2() {
//        Queue queue2 = new Queue("queue2");
//        //设置队列属性
//        return queue2;
//    }
//    //声明路由模式交换机
//    @Bean
//    public DirectExchange ex1() {
//        return new DirectExchange("ex1");
//    }
//    //绑定队列
//    @Bean
//    public Binding bindingQueue1(Queue queue1, @Qualifier("ex1") DirectExchange ex1) {
//        return BindingBuilder.bind(queue1).to(ex1).with("k1");
//    }
//    @Bean
//    public Binding bindingQueue2(Queue queue2, @Qualifier("ex1")DirectExchange ex1) {
//        return BindingBuilder.bind(queue2).to(ex1).with("k2");
//    }
//
//
////    @Bean
////    public CachingConnectionFactory connectionFactory() {
////        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
////        cachingConnectionFactory.setAddresses("192.168.43.7:5672");
////        cachingConnectionFactory.setUsername("ytao");
////        cachingConnectionFactory.setPassword("admin123");
////        cachingConnectionFactory.setVirtualHost("host1");
////        return cachingConnectionFactory;
////    }
////    @Bean
////    public SimpleMessageListenerContainer simpleMessageListenerContainer(CachingConnectionFactory connectionFactory) {
////        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer( connectionFactory);
////        //设置监听队列
////        container.setQueues(queue1(), queue2());
////        container.setConcurrentConsumers(1);                          //消费者数量
////        container.setMaxConcurrentConsumers(5);                       //最大消费者数量
////        container.setDefaultRequeueRejected(false);                   //重回队列
////        container.setAcknowledgeMode(AcknowledgeMode.AUTO);           //签收模式
////        container.setConsumerTagStrategy(new ConsumerTagStrategy() {  //消费端标签策略
////            @Override
////            public String createConsumerTag(String queue) {
////                return queue+"_"+ UUID.randomUUID();
////            }
////        });
////        container.setMessageListener(new ChannelAwareMessageListener() {
////            @Override
////            public void onMessage(Message message, Channel channel) throws Exception {
////                //做消息的处理
////                String messageBody = new String(message.getBody());
////                System.out.println(messageBody);
////            }
////        });
////        return container;
////    }
//}
